I've loved using jQuery these past few months, but I'm really pulling
my hair our here.
The following is the "endpoint" asp code that gets called to populate
my treeview:
<%
rootid = request.querystring("rootid")
json = ""
set Conn = server.CreateObject("ADODB.Connection")
Conn.Open strProvider
if rootid = "source" then
json = "["
set RS = Server.CreateObject("ADODB.RecordSet")
Sql = "select categoryid,categoryname,(select count(*) from
tblcategories where parentid = c1.categoryid) ChildCount from
tblcategories c1 where parentid = 0"
session("errorsql") = sql
set Cmd = Server.CreateObject("ADODB.Command")
Cmd.CommandText = Sql
Cmd.ActiveConnection = Conn
rs.open Cmd
if not RS.EOF then
GotRows = "y"
arrResultSet = RS.GetRows()
numRows = ubound(arrResultSet,2)
For i = 0 to numRows
categoryid = arrResultSet(0,i)
categoryname = arrResultSet(1,i)
childcount = cint(arrResultSet(2,i))
json = json & "{'text': '" & categoryname & "','id':'" & categoryid
& "'"
if childcount > 0 then
json = json & ", 'hasChildren':true"
end if
json = json & "}"
if i < numRows then
json = json & ","
end if
Next
else
GotRows = "n"
json = json & "{'text': 'No Categories have been created'}"
end if
json = json & "]"
RS.close
elseif isnumeric(rootid) and rootid <> "" then
json = "["
set RS = Server.CreateObject("ADODB.RecordSet")
Sql = "select categoryid,categoryname,(select count(*) from
tblcategories where parentid = c1.categoryid) ChildCount from
tblcategories c1 where parentid = ?"
session("errorsql") = sql
set Cmd = Server.CreateObject("ADODB.Command")
Cmd.Parameters.Append CreateIntParameter(Cmd, "rootid", rootid)
Cmd.CommandText = Sql
Cmd.ActiveConnection = Conn
rs.open Cmd
if not RS.EOF then
GotRows = "y"
arrResultSet = RS.GetRows()
numRows = ubound(arrResultSet,2)
For i = 0 to numRows
categoryid = arrResultSet(0,i)
categoryname = arrResultSet(1,i)
childcount = cint(arrResultSet(2,i))
json = json & "{'text': '" & categoryname & "','id':'" & categoryid
& "'"
if childcount > 0 then
json = json & ", 'hasChildren':true"
end if
json = json & "}"
if i < numRows then
json = json & ","
end if
Next
else
GotRows = "n"
end if
json = json & "]"
RS.close
end if
set Cmd = nothing
set RS=nothing
conn.close
set conn=nothing
response.write json
%>
This code produces the following JSON string viewable when I hit the
page directly with the ?rootid=source parameter:
[{'text': 'Cat1.0','id':'1'},{'text': 'Cat1.1','id':'2',
'hasChildren':true},{'text': 'Cat1.2','id':'3'}]
Unless I've received a severe blow to the head, I recognize this as
valid JSON and just what the treeview needs to produce a flat display
of 3 nodes with the second having a '+' sign for expandability.
Here's the frustrating part, when I past that string into the body of
my asp page, comment out the response.write line, save, and run
everything I get the simple tree that I'd expect. When I remove the
JSON string, and uncomment the response.write line, nothing happens.
I've tried flushing the response object, ending the response object,
clearing the response before writing to it, yet nothing seems to work.
Please, please help!